package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.OrderDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.info.Cartinfo;
import com.iflytek.service.OrderService;
import com.iflytek.vo.OrderVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/order")
public class OrderController{
    @Resource
    public OrderService orderService;

    /**
     * 查询所有订单（非分页）findAll
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping("")
    Result<List<OrderVO>> findAll() {
        return orderService.findAll();
    }

    /**
     * 保存订单save
     * @param dto
     * @return
     */
    @ApiOperation("保存")
    @PostMapping("")
    Result<Boolean> saveOrder(@RequestBody OrderDTO dto,HttpServletRequest request) {
        return orderService.saveOrder(dto,request);
    }

    /**
     * 更新订单信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新")
    @PutMapping("")
    Result<Boolean> updateOrder(@RequestBody OrderDTO dto) {
        return orderService.updateOrder(dto);
    }

    /**
     * 前台查询订单列表
     */

    @ApiOperation("前台查询")
    @GetMapping("/page/front")
    Result<PageVO<OrderVO>> findByFront(PageDTO<OrderDTO> dto,HttpServletRequest request) {
        return  orderService.findByFront(dto, request);
    }

    /**
     * 订单付款
     */
    @ApiOperation("订单付款")
    @PutMapping("pay/{id}")
    public Result <Boolean> findByPay(@PathVariable("id")Long id){

        return  orderService.findByPay(id);
    }

    /**
     * 获取订单的确认信息
     */
    @ApiOperation("获取订单的确认信息")
    @PostMapping("/pre")
    public Result<Cartinfo> findByPre(HttpServletRequest request){
        return orderService.findByPre(request);
    }


    /**
     * 订单分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("分页")
    @GetMapping("/page")
    Result<PageVO<OrderVO>> findPage(PageDTO<OrderDTO> dto) {
        return orderService.findPage(dto);
    }


    /**
     * 订单分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("根据id查")
    @PostMapping("/{id}")
    Result<OrderVO> findById(@PathVariable("id") Long id) {
        return orderService.findById(id);
    }

    /**
     * 根据id删除订单deleteById
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("{id}")
    Result<OrderVO> deleteById(@PathVariable("id") Long id) {
        return orderService.deleteById(id);
    }

}

